package com.azt.provider.impl;

import com.azt.api.pojo.RecommendCompany;
import com.azt.api.service.RecommendCompanyService;
import com.azt.model.page.Pagination;
import com.azt.provider.mapper.RecommendCompanyMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class RecommendCompanyServiceImpl implements RecommendCompanyService {

	@Autowired
	private RecommendCompanyMapper recommendMapper;

	@Override
	public List<RecommendCompany> findIndexCompany() {
		RecommendCompany company = new RecommendCompany();
		company.setUpToIndex(1);
		Example example = new Example(RecommendCompany.class);
		example.createCriteria().andEqualTo(company);
		example.orderBy("seq asc");
		return recommendMapper.selectByExample(example);
	}

	@Override
	public Pagination selectMainRecommendCp(int pageno, int pagesize, Map<String, String> params) {
		Page<Object> startPage = PageHelper.startPage(pageno, pagesize);
		List<RecommendCompany> companyList = recommendMapper.selectMainRecommendCp(params);
		Pagination p = new Pagination(startPage, companyList);
		p.setList(companyList);
		p.setParams(params);
		return p;
	}

	@Override
	public void addRecommendCompany(RecommendCompany rc) {
		recommendMapper.insertSelective(rc);
	}

	@Override
	public void editRecommendCompany(RecommendCompany rc) {
		recommendMapper.updateByPrimaryKeySelective(rc);
	}

	@Override
	public RecommendCompany getRecommendCompanyByid(Integer id) {
		return recommendMapper.selectByPrimaryKey(id);
	}

	@Override
	public void delRecommendCompany(Integer id) {
		recommendMapper.deleteByPrimaryKey(id);
	}

	 

}
